﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace MvcEngine.Core.Helpers
{
    public class FileHelper : IFileHelper
    {
        public static IFileHelper Current
        {
            get { return IoC.Resolve<IFileHelper>(); }
        }

        [DebuggerStepThrough]
        public string ReadAllText(string path)
        {
            return File.ReadAllText(path);
        }

        [DebuggerStepThrough]
        public string[] ReadAllLine(string path)
        {
            return File.ReadAllLines(path);
        }

        [DebuggerStepThrough]
        public void WriteAllText(string path, string content)
        {
            File.WriteAllText(path, content);
        }

        public bool Exists(string path)
        {
            return File.Exists(path);
        }

        public string SizeFormat(float size, string formatString)
        {
            if (size < 1024)
                return size.ToString(formatString) + " bytes";

            if (size < Math.Pow(1024, 2))
                return (size / 1024).ToString(formatString) + " kb";

            if (size < Math.Pow(1024, 3))
                return (size / Math.Pow(1024, 2)).ToString(formatString) + " mb";

            if (size < Math.Pow(1024, 4))
                return (size / Math.Pow(1024, 3)).ToString(formatString) + " gb";

            return size.ToString(formatString);
        }
    }
}
